/*
 * HoofdPaneel.java
 *
 * Created on December 6, 2008, 2:47 PM
 */

package tetris.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.Timer;
import tetris.model.blokken.Bord;

/**
 *
 * @author  Batist Leman & Pieter Hens
 */
public class HoofdPaneel extends javax.swing.JPanel implements KeyListener {
    Bord bord = new Bord(10,18,1);
    /** Creates new form HoofdPaneel */
    public HoofdPaneel() {
        initComponents();
 
        bordPaneel1.setBord(bord);
        scorePaneel1.setBord(bord);
        scorePaneel1.setHoofdframe(this);
        //timer = new Timer(1000, bord );
        //timer.start();
        addKeyListener( this );
        bord.addObserver(scorePaneel1);
         bord.addObserver(bordPaneel1);
        

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bordPaneel1 = new tetris.view.BordPaneel();
        scorePaneel1 = new tetris.view.ScorePaneel();

        javax.swing.GroupLayout bordPaneel1Layout = new javax.swing.GroupLayout(bordPaneel1);
        bordPaneel1.setLayout(bordPaneel1Layout);
        bordPaneel1Layout.setHorizontalGroup(
            bordPaneel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 208, Short.MAX_VALUE)
        );
        bordPaneel1Layout.setVerticalGroup(
            bordPaneel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 429, Short.MAX_VALUE)
        );

        scorePaneel1.setLayout(new java.awt.FlowLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bordPaneel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scorePaneel1, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(bordPaneel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(scorePaneel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    //private Timer timer;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private tetris.view.BordPaneel bordPaneel1;
    private tetris.view.ScorePaneel scorePaneel1;
    // End of variables declaration//GEN-END:variables

    public void keyTyped(KeyEvent arg0) {
 
    }

    public void keyPressed(KeyEvent evt) {
           switch(evt.getKeyCode()){
        case  KeyEvent.VK_LEFT:
            bord.beweegX(-1);
            break;
        case  KeyEvent.VK_RIGHT:
            bord.beweegX(1);
            break;
        case  KeyEvent.VK_UP:
            bord.toggle();
            break;
        case  KeyEvent.VK_DOWN:
            bord.beweegY(1);
            break;
           
           case  KeyEvent.VK_SPACE:
            bord.verwijderLijn(5);
            break;
           }
    }

    public void keyReleased(KeyEvent arg0) {
 
    }

}
